package com.pureut.storage.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pureut.storage.dto.InventoryBalanceDto;
import com.pureut.storage.mapper.PublicMaterialMapper;
import com.pureut.storage.mapper.WarehouseReportMapper;
import com.pureut.storage.service.WarehouseReportService;
import com.pureut.storage.utils.DocumentTypeEnum;
import com.sale.common.core.constant.CacheNames;
import com.sale.common.core.domain.R;
import com.sale.common.mybatis.core.page.PageQuery;
import com.sale.common.mybatis.core.page.TableDataInfo;
import com.sale.common.redis.utils.CacheUtils;
import com.sale.storage.api.dto.InvoicingReportDto;
import com.sale.storage.api.vo.InventoryBalanceVo;
import com.sale.system.api.RemoteInventoryAccountingService;
import com.sale.system.api.RemoteUnitService;
import com.sale.system.api.domain.SysAuxiliary;
import com.sale.system.api.domain.SysAuxiliaryUnitDetail;
import com.sale.system.api.model.MaterialUnitDto;
import io.seata.spring.annotation.GlobalTransactional;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;


/**
 * TODO
 * 仓库报表
 *
 * @Description
 * @Author Try
 * @Date 2023/9/11 13:56
 **/
@Service
public class WarehouseReportServiceImpl implements WarehouseReportService {

    @Resource
    private WarehouseReportMapper warehouseReportMapper;

    @DubboReference
    RemoteUnitService remoteUnitService;

    @Resource
    private PublicMaterialMapper publicMaterialMapper;

    @DubboReference
    RemoteInventoryAccountingService remoteInventoryAccountingService;

    /**
     * 库存余额表
     *
     * @param inventoryBalanceVo
     * @return
     */
    @Override
    @GlobalTransactional(rollbackFor = Exception.class)
    public TableDataInfo<InventoryBalanceDto> getInventoryBalance(PageQuery pageQuery, InventoryBalanceVo inventoryBalanceVo) {
        //查询基本列表
        //   Page<InventoryBalanceDto> list = warehouseReportMapper.getInventoryBalance(pageQuery.build(), inventoryBalanceVo);


     /*   for (InventoryBalanceDto inventoryBalanceDto : list.getRecords()) {
            //辅助属性
            List<SysAuxiliary> statsArray = CacheUtils.get(CacheNames.SYS_GINSENG + "_" + inventoryBalanceDto.getTenantId(), String.valueOf(inventoryBalanceDto.getMaterialId()));
            inventoryBalanceDto.setAuxiliaryAttribute(statsArray);

            MaterialUnitDto unitByCode = remoteUnitService.getUnitByCode(inventoryBalanceDto.getMaterialCode());

            //单位
            inventoryBalanceDto.setMaterialUnitDict(unitByCode.getUnitName());

            //多单位
            inventoryBalanceDto.setMoreMaterialUnitDict(unitByCode.getAuxiliaryUnit());

            //单位成本
            BigDecimal bigDecimal = new BigDecimal(inventoryBalanceDto.getCostSum());

            BigDecimal bigDecimal1 = new BigDecimal(inventoryBalanceDto.getUnitQuantity());

            //类别
            if("1".equals(inventoryBalanceDto.getMaterialCategory())){
                inventoryBalanceDto.setMaterialCategory("原料");
            }else{
                inventoryBalanceDto.setMaterialCategory("成品");
            }

           if (!"0".equals(inventoryBalanceDto.getUnitQuantity())){
               String s = bigDecimal.divide(bigDecimal1, 2,  RoundingMode.HALF_UP).toString();
               inventoryBalanceDto.setUnitCost(s);
           }else{
               inventoryBalanceDto.setUnitCost("0");
           }


            //多单位
            List<SysAuxiliaryUnitDetail> list1 = unitByCode.getList();
            //定义多单位数量
            String moreUnit = "";

            String num = inventoryBalanceDto.getUnitQuantity();

            if (list1 != null && list1.size() != 0) {

                for (SysAuxiliaryUnitDetail sysAuxiliaryUnitDetail : list1) {
                    String unitQuantity = sysAuxiliaryUnitDetail.getUnitQuantity();
                    BigDecimal number1 = new BigDecimal(num);
                    BigDecimal number2 = new BigDecimal(unitQuantity);
                    BigDecimal[] bigDecimals = number1.divideAndRemainder(number2);
                    // 数组的第一个值为商，第二个值为余数
                    String discuss = bigDecimals[0].toString();
                    String remainder = bigDecimals[1].toString();

                    //如果直接被整除说明刚好满足当前最大单位
                    if ("0".equals(remainder)) {
                        moreUnit = moreUnit + discuss + sysAuxiliaryUnitDetail.getUnitName();
                        break;
                    } else {
                        if (sysAuxiliaryUnitDetail == list1.get(list1.size() - 1)) {
                            moreUnit = moreUnit + remainder + unitByCode.getUnitName();
                        }

                        if ("0".equals(discuss)) {
                            continue;
                        }

                        //没有被整除
                        moreUnit = moreUnit + discuss + sysAuxiliaryUnitDetail.getUnitName();
                        //修改num的值为当前的余数
                        num = remainder;

                    }

                }

                //如果多单位数量为“”说明不满足其他的辅助单位,只满足最小单位
                if ("".equals(moreUnit)) {
                    moreUnit = inventoryBalanceDto.getUnitQuantity() + "" + unitByCode.getUnitName();
                }

            }
            inventoryBalanceDto.setAuxiliaryUnitName(moreUnit);

        }*/
        Page<InventoryBalanceDto> list = null;
        return TableDataInfo.build(list);
    }

    /**
     * 进销存统计报表
     *
     * @param
     * @param inventoryBalanceVo
     * @return
     */
    public List<InvoicingReportDto> getInvoicingReport(InventoryBalanceVo inventoryBalanceVo) {

        //单位
        R<MaterialUnitDto> unitDataByCode = remoteUnitService.getUnitDataByCode(null);
        Map<Long, String> unitMap = unitDataByCode.getData().getUnitMap();

        //判断是先进先出还是加权平均
        int type = remoteInventoryAccountingService.getCostAccountingMethod();

        //如果是本月
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM");
        String format = simpleDateFormat.format(new Date());

        //得到当前月的1号
        format = format + "-01";

        if (inventoryBalanceVo.getBeginTime() != null && inventoryBalanceVo.getEndTime() != null) {
            format = inventoryBalanceVo.getBeginTime();
            inventoryBalanceVo.setFormat(format);
        }

        /**
         * 查询出入库的物料编码
         */
        List<InvoicingReportDto> materialCodeList = null;

        if (inventoryBalanceVo.getBeginTime() != null && inventoryBalanceVo.getEndTime() != null) {
            materialCodeList = warehouseReportMapper.getMaterialCodeList(inventoryBalanceVo);
        } else {
            materialCodeList = warehouseReportMapper.getMaterialCodeList1(format);
        }

        /**
         * 查询所有物料编码入库的信息
         */
        List<InvoicingReportDto> inStockInfo = warehouseReportMapper.getInStockInfo(new InventoryBalanceVo());

        Map<String, List<InvoicingReportDto>> collect = inStockInfo.stream().collect(Collectors.groupingBy(InvoicingReportDto::getMaterialCode));

        /**
         * 查询所有的物料出入库
         */
        List<InvoicingReportDto> list = warehouseReportMapper.getWarehouseInfo(inventoryBalanceVo);

        Map<String, List<InvoicingReportDto>> mapInfo = list.stream().collect(Collectors.groupingBy(InvoicingReportDto::getMaterialCode));

        List<InvoicingReportDto> list1 = new ArrayList<>();

        for (InvoicingReportDto invoicingReportDto : materialCodeList) {
            List<InvoicingReportDto> invoicingReportDtoList = mapInfo.get(invoicingReportDto.getMaterialCode());

            //通过物料编码获取期初
            if (invoicingReportDtoList != null) {

                for (int i = 0; i < invoicingReportDtoList.size(); i++) {
                    InvoicingReportDto invoicingReportDto1 = invoicingReportDtoList.get(i);
                    //类别
                    if ("1".equals(invoicingReportDto1.getCodingType())) {
                        invoicingReportDto1.setCodingType("原料");
                    } else {
                        invoicingReportDto1.setCodingType("成品");
                    }

                    //辅助属性
                    List<SysAuxiliary> statsArray = CacheUtils.get(CacheNames.SYS_GINSENG + "_" + invoicingReportDto1.getTenantId(), String.valueOf(invoicingReportDto1.getMaterialId()));
                    invoicingReportDto1.setAuxiliaryAttribute(statsArray);
                    //单位
                    if (invoicingReportDto1.getMaterialUnit() != null) {
                        invoicingReportDto1.setMaterialUnit(unitMap.get(Long.parseLong(invoicingReportDto1.getMaterialUnit())));
                    }

                    //单据类型
                    String value = DocumentTypeEnum.getValue(Integer.parseInt(invoicingReportDto1.getDocumentType()));


                    //结存金额(如果是第一条,结存金额=期初+入库金额，如果不是结存金额=上一条结存金额+当前入库金额)
                    //结存金额=期初+入库金额
                    BigDecimal qc = new BigDecimal(invoicingReportDto.getOpeningBalance());

                    //期初结存数量
                    BigDecimal qcNum = new BigDecimal(invoicingReportDto.getBalanceNum());

                    BigDecimal ck = null;


                    if (invoicingReportDto1.getOutStorageAmount() != null && !"".equals(invoicingReportDto1.getOutStorageAmount())) {
                        ck = new BigDecimal(invoicingReportDto1.getOutStorageAmount());
                    } else {
                        ck = new BigDecimal("0");
                    }

                    //设置出库信息
                    List<InvoicingReportDto> invoicingReportDtoList1 = collect.get(invoicingReportDto1.getMaterialCode());

                    //定义出库金额
                    String outAmount = "0";

                    //定义出库的数量
                    int outNum = 0;

                    if (invoicingReportDto1.getOutStorageNum() != null) {
                        outNum = Integer.parseInt(invoicingReportDto1.getOutStorageNum());
                    }
                    if (type == 2) {
                        if ("2".equals(invoicingReportDto1.getDocumentType()) || "3".equals(invoicingReportDto1.getDocumentType()) || "5".equals(invoicingReportDto1.getDocumentType()) || "10".equals(invoicingReportDto1.getDocumentType())) {
                            //出库的结存单价根据先进先出的原则计算单价
                            for (InvoicingReportDto reportDto : invoicingReportDtoList1) {
                                //获取当前单价
                                String inStoragePrice = reportDto.getInStoragePrice();
                                //获取当前入库单数量
                                String inStorageNum1 = reportDto.getInStorageNum();


                                //如果当前的出库数量小于入库的数量,则结存单价等于入库单价
                                if (outNum < Integer.parseInt(inStorageNum1)) {
                                    invoicingReportDto1.setBalancePrice(inStoragePrice);

                                    outAmount = new BigDecimal(outAmount).add(new BigDecimal(outNum).multiply(new BigDecimal(inStoragePrice))).toString();
                                    break;
                                } else {
                                    //剩余出库数量
                                    outNum = outNum - Integer.parseInt(inStorageNum1);
                                    //出库金额
                                    outAmount = new BigDecimal(outAmount).add(new BigDecimal(outNum).multiply(new BigDecimal(inStoragePrice))).toString();

                                }
                            }
                            //出库金额
                            invoicingReportDto1.setOutStorageAmount(outAmount);
                            ck = new BigDecimal(outAmount);
                        } else {

                            invoicingReportDto1.setBalancePrice(invoicingReportDto1.getInStoragePrice());
                        }
                    }


                    //出库数量
                    BigDecimal outStorageNum = null;

                    if (invoicingReportDto1.getOutStorageNum() != null && !"".equals(invoicingReportDto1.getOutStorageNum())) {
                        outStorageNum = new BigDecimal(invoicingReportDto1.getOutStorageNum());
                    } else {
                        outStorageNum = new BigDecimal("0");
                    }

                    BigDecimal rk = null;

                    if (invoicingReportDto1.getInStorageAmount() != null && !"".equals(invoicingReportDto1.getInStorageAmount())) {
                        rk = new BigDecimal(invoicingReportDto1.getInStorageAmount());
                    } else {
                        rk = new BigDecimal("0");
                    }

                    //入库数量
                    BigDecimal inStorageNum = null;

                    if (invoicingReportDto1.getInStorageNum() != null && !"".equals(invoicingReportDto1.getInStorageNum())) {
                        inStorageNum = new BigDecimal(invoicingReportDto1.getInStorageNum());
                    } else {
                        inStorageNum = new BigDecimal("0");
                    }

                    //期初结存单价
                    BigDecimal qcPrice = null;
                    if (invoicingReportDto1.getBalanceNum() == null) {
                        qcPrice = new BigDecimal("0");
                    } else {
                        qcPrice = qc.divide(qcNum, 2, RoundingMode.HALF_UP);
                    }

                    if (i == 0) {
                        //如果第一条单据类型是入库，则期初+入库金额，否则减去入库金额
                        if ("2".equals(invoicingReportDto1.getDocumentType()) || "3".equals(invoicingReportDto1.getDocumentType()) || "5".equals(invoicingReportDto1.getDocumentType()) || "10".equals(invoicingReportDto1.getDocumentType())) {

                            String balanceAmount = qc.subtract(ck).toString();
                            invoicingReportDto1.setBalanceAmount(balanceAmount);

                            //结存数量
                            String balanceNum = qcNum.subtract(outStorageNum).toString();
                            invoicingReportDto1.setBalanceNum(balanceNum);

                            if (type == 1) {
                                //出库单价
                                invoicingReportDto1.setBalancePrice(qcPrice.toString());
                                //出库金额
                                invoicingReportDto1.setOutStorageAmount(qcPrice.multiply(outStorageNum).toString());
                            }

                        } else {

                            String balanceAmount = qc.add(rk).toString();
                            invoicingReportDto1.setBalanceAmount(balanceAmount);

                            //结存数量
                            String balanceNum = qcNum.add(inStorageNum).toString();
                            invoicingReportDto1.setBalanceNum(balanceNum);

                        }
                    } else {
                        //如果不是结存金额=上一条结存金额+当前入库金额
                        //获取上一条结存金额
                        InvoicingReportDto invoicingReportDto2 = invoicingReportDtoList.get(i - 1);
                        String balanceAmount = invoicingReportDto2.getBalanceAmount();

                        String balanceNum = invoicingReportDto2.getBalanceNum();
                        BigDecimal jc = new BigDecimal(balanceAmount);


                        BigDecimal jcNum = new BigDecimal(balanceNum);
                        if ("2".equals(invoicingReportDto1.getDocumentType()) || "3".equals(invoicingReportDto1.getDocumentType()) || "5".equals(invoicingReportDto1.getDocumentType()) || "10".equals(invoicingReportDto1.getDocumentType())) {
                            //结存金额
                            String balanceAmount1 = jc.subtract(ck).toString();
                            invoicingReportDto1.setBalanceAmount(balanceAmount1);

                            //结存数量
                            String balanceNum1 = jcNum.subtract(outStorageNum).toString();
                            invoicingReportDto1.setBalanceNum(balanceNum1);
                            if (type == 1) {
                                //出库单价
                                invoicingReportDto1.setOutStoragePrice(invoicingReportDto2.getBalancePrice());
                                //出库金额
                                BigDecimal bigDecimal = new BigDecimal(invoicingReportDto2.getBalancePrice());
                                invoicingReportDto1.setOutStorageAmount(bigDecimal.multiply(outStorageNum).toString());
                                //结存单价计算
                                BigDecimal bigDecimal1 = new BigDecimal(balanceAmount1);
                                BigDecimal bigDecimal2 = new BigDecimal(balanceNum1);
                                if (balanceNum1.equals("0")) {
                                    invoicingReportDto1.setBalancePrice("0");
                                } else {
                                    invoicingReportDto1.setBalancePrice(bigDecimal1.divide(bigDecimal2, 2, RoundingMode.HALF_UP).toString());
                                }
                                //结存金额(加权平均)
                                String balanceAmount2 = jc.subtract(new BigDecimal(invoicingReportDto1.getOutStorageAmount())).toString();
                                invoicingReportDto1.setBalanceAmount(balanceAmount2);
                            }

                        } else {

                            String balanceAmount1 = jc.add(rk).toString();
                            invoicingReportDto1.setBalanceAmount(balanceAmount1);

                            //结存数量
                            String balanceNum1 = jcNum.add(inStorageNum).toString();
                            invoicingReportDto1.setBalanceNum(balanceNum1);
                        }
                    }

                    //加权平均
                    if (type == 1) {
                        //算出结存单价
                        BigDecimal bigDecimal = new BigDecimal(invoicingReportDto1.getBalanceAmount());
                        BigDecimal bigDecimal1 = new BigDecimal(invoicingReportDto1.getBalanceNum());
                        if ("0".equals(invoicingReportDto1.getBalanceNum())) {
                            invoicingReportDto1.setBalancePrice("0");
                        } else {
                            invoicingReportDto1.setBalancePrice(bigDecimal.divide(bigDecimal1, 2, RoundingMode.HALF_UP).toString());
                        }
                    }
//                    else{
//                        //结存单价，如果是入库，结存单价等于入库单价
//                        if ("2".equals(invoicingReportDto1.getDocumentType())||"3".equals(invoicingReportDto1.getDocumentType())||"5".equals(invoicingReportDto1.getDocumentType())||"10".equals(invoicingReportDto1.getDocumentType())){
//                            //出库的结存单价根据先进先出的原则计算单价
//                            //设置出库信息
//                            List<InvoicingReportDto> invoicingReportDtoList1 = collect.get(invoicingReportDto1.getMaterialCode());
//
//                            //定义出库金额
//                            String outAmount = "0";
//
//                            //定义出库的数量
//                            int outNum = 0;
//
//                            if (invoicingReportDto1.getOutStorageNum()!=null){
//                                outNum = Integer.parseInt(invoicingReportDto1.getOutStorageNum());
//                            }
//
//                            for (InvoicingReportDto reportDto : invoicingReportDtoList1) {
//                                //获取当前单价
//                                String inStoragePrice = reportDto.getInStoragePrice();
//                                //获取当前入库单数量
//                                String inStorageNum1 = reportDto.getInStorageNum();
//
//
//                                //如果当前的出库数量小于入库的数量,则结存单价等于入库单价
//                                if (outNum<Integer.parseInt(inStorageNum1)){
//                                    invoicingReportDto1.setBalancePrice(inStoragePrice);
//
//                                    outAmount = new BigDecimal(outAmount).add(new BigDecimal(outNum).multiply(new BigDecimal(inStoragePrice))).toString();
//                                    break;
//                                }else{
//                                    //剩余出库数量
//                                    outNum = outNum- Integer.parseInt(inStorageNum1);
//                                    //出库金额
//                                    outAmount = new BigDecimal(outAmount).add(new BigDecimal(outNum).multiply(new BigDecimal(inStoragePrice))).toString();
//
//                                }
//                            }
//                            //出库金额
//                            invoicingReportDto1.setOutStorageAmount(outAmount);
//                        }else{
//                            invoicingReportDto1.setBalancePrice(invoicingReportDto1.getInStoragePrice());
//                        }
                    //}
                    invoicingReportDto1.setDocumentType(value);
                    if (invoicingReportDto1.getBalancePrice()!=null){
                        if (invoicingReportDto1.getBalancePrice().contains("-")) {
                            invoicingReportDto1.setBalancePrice(invoicingReportDto1.getBalancePrice().replace("-", ""));
                        }
                    }

                }

                InvoicingReportDto invoicingReportDto1 = new InvoicingReportDto();
                invoicingReportDto1.setDocumentType(invoicingReportDto.getOpeningBalance());
                invoicingReportDto1.setMaterialName(invoicingReportDto.getMaterialName());
                invoicingReportDto1.setMaterialCode(invoicingReportDto.getMaterialCode());
                invoicingReportDto1.setType(1);


                if (type == 1) {
                    //期初金额
                    invoicingReportDto1.setBalanceAmount(invoicingReportDto.getOpeningBalance());
                    //期初单价
                    if (invoicingReportDto.getBalanceNum() == null || "".equals(invoicingReportDto.getBalanceNum())) {
                        invoicingReportDto1.setBalancePrice("0");
                    } else {
                        String balanceNum = invoicingReportDto.getBalanceNum();
                        if ("0".equals(balanceNum)) {
                            invoicingReportDto1.setBalancePrice("0");
                        } else {
                            invoicingReportDto1.setBalancePrice(new BigDecimal(invoicingReportDto.getOpeningBalance()).divide(new BigDecimal(invoicingReportDto.getBalanceNum()), 2, RoundingMode.HALF_UP).toString());
                        }

                    }
                    //期初数量
                    invoicingReportDto1.setBalanceNum(invoicingReportDto.getBalanceNum());

                }

                invoicingReportDtoList.add(0, invoicingReportDto1);
                list1.addAll(invoicingReportDtoList);
            }

        }
        return list1;
    }

    @Override
    public TableDataInfo<InventoryBalanceDto> getInventoryBalance2(PageQuery pageQuery, InventoryBalanceVo inventoryBalanceVo) {
        //查询基本列表
        Page<InventoryBalanceDto> list = warehouseReportMapper.getInventoryBalance(pageQuery.build(), inventoryBalanceVo);


        for (InventoryBalanceDto inventoryBalanceDto : list.getRecords()) {
            //辅助属性
            List<SysAuxiliary> statsArray = CacheUtils.get(CacheNames.SYS_GINSENG + "_" + inventoryBalanceDto.getTenantId(), String.valueOf(inventoryBalanceDto.getMaterialId()));
            inventoryBalanceDto.setAuxiliaryAttribute(statsArray);

            MaterialUnitDto unitByCode = remoteUnitService.getUnitByCode(inventoryBalanceDto.getMaterialCode());

            //单位
            inventoryBalanceDto.setMaterialUnitDict(unitByCode.getUnitName());

            //多单位
            inventoryBalanceDto.setMoreMaterialUnitDict(unitByCode.getAuxiliaryUnit());

            //单位成本
            BigDecimal bigDecimal = new BigDecimal(inventoryBalanceDto.getCostSum());

            BigDecimal bigDecimal1 = new BigDecimal(inventoryBalanceDto.getUnitQuantity());

            //类别
            if ("1".equals(inventoryBalanceDto.getMaterialCategory())) {
                inventoryBalanceDto.setMaterialCategory("原料");
            } else {
                inventoryBalanceDto.setMaterialCategory("成品");
            }

            if (!"0".equals(inventoryBalanceDto.getUnitQuantity())) {
                String s = bigDecimal.divide(bigDecimal1, 2, RoundingMode.HALF_UP).toString();
                inventoryBalanceDto.setUnitCost(s);
            } else {
                inventoryBalanceDto.setUnitCost("0");
            }


            //多单位
            List<SysAuxiliaryUnitDetail> list1 = unitByCode.getList();
            //定义多单位数量
            String moreUnit = "";

            String num = inventoryBalanceDto.getUnitQuantity();

            if (list1 != null && list1.size() != 0) {

                for (SysAuxiliaryUnitDetail sysAuxiliaryUnitDetail : list1) {
                    String unitQuantity = sysAuxiliaryUnitDetail.getUnitQuantity();
                    BigDecimal number1 = new BigDecimal(num);
                    BigDecimal number2 = new BigDecimal(unitQuantity);
                    BigDecimal[] bigDecimals = number1.divideAndRemainder(number2);
                    // 数组的第一个值为商，第二个值为余数
                    String discuss = bigDecimals[0].toString();
                    String remainder = bigDecimals[1].toString();

                    //如果直接被整除说明刚好满足当前最大单位
                    if ("0".equals(remainder)) {
                        moreUnit = moreUnit + discuss + sysAuxiliaryUnitDetail.getUnitName();
                        break;
                    } else {
                        if (sysAuxiliaryUnitDetail == list1.get(list1.size() - 1)) {
                            moreUnit = moreUnit + remainder + unitByCode.getUnitName();
                        }

                        if ("0".equals(discuss)) {
                            continue;
                        }

                        //没有被整除
                        moreUnit = moreUnit + discuss + sysAuxiliaryUnitDetail.getUnitName();
                        //修改num的值为当前的余数
                        num = remainder;

                    }

                }

                //如果多单位数量为“”说明不满足其他的辅助单位,只满足最小单位
                if ("".equals(moreUnit)) {
                    moreUnit = inventoryBalanceDto.getUnitQuantity() + "" + unitByCode.getUnitName();
                }

            }
            inventoryBalanceDto.setAuxiliaryUnitName(moreUnit);

        }
        return TableDataInfo.build(list);
    }

}
